package task5_06;

import java.util.ArrayList;
import java.util.Iterator;

public class UserDaoList implements UserDao {
    //创建集合
    ArrayList<User> userArrayList = new ArrayList<User>();

    @Override
    public void register(User user) {
        if (!userArrayList.contains(user)) {
            userArrayList.add(user);
        }
    }

    @Override
    public boolean login(String name, String password) {
        for (int i = 0; i < userArrayList.size(); i++) {
            if (userArrayList.get(i).getUsername().equals(name) &&
                    userArrayList.get(i).getPassword().equals(password)) {
                return true;
            }
        }
        return false;
    }

    @Override
    public void see() {
     /* for(User user:userArrayList){
          System.out.println(user.getUsername()+"\t"+user.getPassword());
      }*/
      Iterator iterator=userArrayList.iterator();
      while(iterator.hasNext()){
          System.out.println(iterator.next());
      }
    }
}
